app.controller("userController",function($scope,$controller,userService){
    $controller("baseController",{$scope:$scope});
    $scope.list = [];
    $scope.user = {};
    $scope.searchEntity = {};

    $scope.search = function(page,rows){
        userService.findPage(page,rows,$scope.searchEntity).then(function(result){
            $scope.list = result.data.rows;
            $scope.pageModel.totalItems = result.data.total;
        });
    };
    $scope.save = function(){
        if($scope.user.uid){
            userService.update($scope.user).then(function(result){
                if(result.data.success){
                    $scope.reloadList();
                }else{
                    alert(result.data.message);
                }
            });
        }else{
            userService.save($scope.user).then(function(result){
                if(result.data.success){
                    $scope.reloadList();
                }else{
                    alert(result.data.message);
                }
            });
        }
    };
    $scope.edit = function(uid){
        userService.edit(uid).then(function(result){
            $scope.user = result.data;
        });
    }
    $scope.dele = function(){
        userService.dele($scope.selectedId).then(function(result){
            if(result.data.success){
                $scope.reloadList();
            }else{
                alert(result.data.message);
            }
        });
    }
});